package com.loanapp.server.market.provider.modular.bbs.api.impl;

import com.github.pagehelper.PageInfo;
import com.loanapp.server.market.api.bbs.api.PostApi;
import com.loanapp.server.market.api.bbs.entity.Post;
import com.loanapp.server.market.api.bbs.query.PostQuery;
import com.loanapp.server.market.provider.modular.bbs.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(PostApi.mapping)
public class PostApiImpl implements PostApi {

    @Autowired
    PostService postService;

    @PostMapping
    public PageInfo<Map<String, Object>> getPostListPage(@RequestBody PostQuery query) throws Exception {
        return   postService.getPostListPage(query,query.getPageParams());
    }

    @PostMapping
    public Map<String, Object> getPostWithCommentById(@RequestParam(required = false)Long id) throws Exception {
        return postService.getPostWithCommentById(id);
    }

    @PostMapping
    public Long Insert(@RequestBody Post post) throws Exception {
        return postService.Insert(post);
    }

    @PostMapping
    public boolean CanPost(@RequestParam(required = false) Long id) throws Exception {
        return postService.CanPost(id);
    }
}
